﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MVC3MusicStore.Models;

namespace MVC3MusicStore.Controllers
{
    public class HomeController : Controller
    {
        MusicStoreEntities db = new MusicStoreEntities();

        //
        // GET: /Home/

        /// <summary>
        /// 这是主页
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            //return View();
            //return "Hello World";
            var albums = GetTopSellingAlbums(5); return View(albums);
        }

        /// <summary>
        /// 手机端主页
        /// </summary>
        /// <returns></returns>
        public ActionResult mIndex() {
            var albums = GetTopSellingAlbums(5); return View(albums);
        }  

        private List<Album> GetTopSellingAlbums(int count)
        {
            // Group the order details by album and return
            // the albums with the highest count
            return db.Albums
            .OrderByDescending(a => a.OrderDetails.Count())
            .Take(count)
            .ToList();
        }

    }
}
